<?php
require 'sql.php';
require 'sanitize.php';
require 'vaildateLogin.php';
$conn = mysql_connect($server, $user, $passwd) or die('Could not connect to SQL server ' .mysql_error());
mysql_select_db($database, $conn) or die('Could not connect to given database' .mysql_error());

include 'users.php';
include 'friends.php';
include 'players.php';
include 'messages.php';
include 'friendsrequests.php';
include 'leaguescoreboard.php';
include 'leagueinvite.php';
include 'team.php';
include 'leagues.php';

// Fix this
$_SGET=sanitize($_GET);
$_SPOST=sanitize($_POST);
$_SREQUEST=sanitize($_REQUEST);


//echo $_SERVER['REQUEST_METHOD'];
if (isset($_SREQUEST['accesstoken']) && isset($_SREQUEST['accesstoken'])){
	$valid=validateLogin($_SREQUEST['auid'],$_SREQUEST['accesstoken']);
}else{
	$valid=false;
}
if ($valid){
	$auid=$_SREQUEST['auid'];
}

switch($_SREQUEST['method']){
	case 'leaguescoreboard':
		leaguescoreboard();
		break;
	case 'user'		:
		user();
		break;
	case 'player'	:
		player();
		break;
	case 'team'		:
		team();
		break;
	case 'league'	:
		league();
		break;
	case 'friends'	:
		friends();
		break;
	case 'messages'	:
		messages();
		break;
	case 'friendrequests':
		friendrequest();
		break;
	case 'joinleague':
		joinleague();
		break;
	case 'leagueinvite':
		leagueinvite();
		break;
	default:
		print '{"error":"bad request"}';
}

mysql_close();
?>